<!DOCTYPE html>
<meta charset="utf-8">
	<link rel='stylesheet' href='./plugins/css/pluginsCss.css' />
	<link rel='stylesheet' href='./plugins/plugins.css' />
	<link rel='stylesheet' href='./css/luckysheet.css' />
	<link rel='stylesheet' href='./assets/iconfont/iconfont.css' />
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script src="./plugins/js/plugin.js"></script>
	<script src="./luckysheet.umd.js"></script>

<div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height:100%;left: 0px;top: 0px;"></div>
<script>
    $(function () {
        var name = "";
        while(name.length == 0){
            name = prompt("请输入昵称")
        }

        var autoSave;
        //配置项
        var options = {
            lang: 'zh',
            container: 'luckysheet',
            allowUpdate: true,
            loadUrl:"http://"+ location.host +"/get",
            hook:{
                updated:function(e){
                    //监听更新,并在3s后自动保存
                    if(autoSave) clearTimeout(autoSave)
                    $(luckysheet_info_detail_save).text("已修改")
                    autoSave = setTimeout(function(){
                        var excel = luckysheet.getAllSheets();
                        //去除临时数据,减小体积
                        for(var i in excel) excel[i].data = undefined
                        $.post(
                            "http://" + location.host + "/set",
                            {jsonExcel:JSON.stringify(excel)},
                            function(){
                                $(luckysheet_info_detail_save).text("已保存")
                            })
                    },3 * 1000)
                    return true;
                }
            },
            updateUrl: "ws://" + location.hostname +":11551/" + name
        }

        console.log(JSON.stringify(options))
        luckysheet.create(options)
    })
</script>